package com.doodle.common.drawable;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.doodle.common.data.AsyncResource;
import com.doodle.common.data.DataAdapter;
import com.doodle.common.utils.BitmapUtils;
import com.doodle.common.utils.ThreadPool;

public class ResourceDrawable extends MeasuredAsyncDrawable {

	private int mResId;
	private Context mContext;
	
	public ResourceDrawable(Context context, int resId, int width, int height, AsyncResource.JobExecutor<Drawable> jobExecutor, int id, DataAdapter.DataLoadedListener listener) {
		super(width, height, BitmapUtils.FIT_LENGTH_LARGGER, DRAWABLE_TYPE_ICON, jobExecutor, null, id, listener);
		mContext = context;
		mResId = resId;
	}

	@Override
	protected ThreadPool.Job<Drawable> requestDrawable() {
		return new ResourceDrawableJob();
	}

	@Override
	protected void recycleDrawable(Drawable drawable) {

	}

	private class ResourceDrawableJob implements ThreadPool.Job<Drawable> {
		@Override
		public Drawable run(ThreadPool.JobContext jc) {
			if (mResId != -1) {
				return mContext.getResources().getDrawable(mResId);
			}
			return null;
		}
	}
}
